package com.team5.mapper;

import java.util.List;

import com.team5.entity.NewStocks;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface NewStocksMapper {
    @Select("select * from \"SCOTT\".NEWDATE where id=#{id}")
    NewStocks findById(Integer id);
    @Select("select * from \"SCOTT\".NEWDATE")
    NewStocks[] findAll();
    @Select("select * from \"SCOTT\".NEWDATE ORDER BY SSDATE DESC ")
    List<NewStocks> list();
    // 新增操作
    @Insert("INSERT INTO \"SCOTT\".NEWDATE (id, name, SSDATE) VALUES (#{id}, #{name}, #{SSDate})")
    @SelectKey(statement = "SELECT seq_stock.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
    int insert(NewStocks newStocks);
    // 更新操作
    @Update("UPDATE \"SCOTT\".NEWDATE SET name = #{name}, SSDATE = #{SSDate} WHERE id = #{id}")
    int update(NewStocks newStocks);
    @Update("UPDATE \"SCOTT\".NEWDATE SET SSDate = #{newStocks.SSDate} "
            + "WHERE name = #{newStocks.name}")
    int updateByName(@Param("newStocks") NewStocks newStocks);
    // 根据 ID 删除操作
    @Delete("DELETE FROM \"SCOTT\".NEWDATE WHERE id = #{id}")
    int deleteById(Integer id);
    @Delete("DELETE FROM \"SCOTT\".NEWDATE WHERE name=#{name}")
    int deleteByName(String name);
    @Delete("DELETE FROM \"SCOTT\".NEWDATE")
    int deleteAll();
}
